/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGE_KNIFE_C_IMAGEKNIFE_OPTION_H
#define IMAGE_KNIFE_C_IMAGEKNIFE_OPTION_H

#include <map>
#include <string>
#include <functional>
#include <arkui/native_type.h>
#include "imageknife_loader.h"
#include "image_source.h"

namespace ImageKnifeC {

class ImageKnifeOption {
public:
    // 主图资源: STRING | PIXELMAP | RESOURCE
    ImageSource loadSrc;
    // 占位图: STRING | PIXELMAP | RESOURCE
    ImageSource placeholderSrc;
    // error占位图: STRING | PIXELMAP | RESOURCE
    ImageSource errorholderSrc;

    std::multimap<std::string, std::string> httpHeaders;

    std::string signature;

    int priority;

    // 主图填充效果 默认为cover
    ArkUI_ObjectFit objectFit = ARKUI_OBJECT_FIT_CONTAIN;
    // 占位图填充效果 默认为cover
    ArkUI_ObjectFit placeholderObjectFit = ARKUI_OBJECT_FIT_CONTAIN;
    // 错误图填充效果 默认为cover
    ArkUI_ObjectFit errorholderObjectFit = ARKUI_OBJECT_FIT_CONTAIN;

    std::shared_ptr<OnLoadCallBack> onLoadListener = nullptr;
    // 监听网络下载进度回调
    std::function<void(double progress)> progressListener = nullptr;
    // 加载显示完成后的回调 可映射ArtTs的onComplete
    std::function<void(EventImage eventImage)> onComplete = nullptr;

    Context context;

    std::shared_ptr<ImageKnifeLoader> imageLoader = nullptr;

    // 用户自定义数据类型，可在自定义拦截器中取得使用
    void* customData = nullptr;
    // 用户自定义finalize回调，可用来析构用户自定义数据
    std::function<void(void* customData)> onFinalize = nullptr;

    virtual ~ImageKnifeOption()
    {
        if (onFinalize != nullptr) {
            onFinalize(customData);
        }
    }
};

} // end of namespace

#endif // IMAGE_KNIFE_C_IMAGEKNIFE_OPTION_H
